\name{GVECid}
\alias{GVECid}
%- Also NEED an '\alias' for EACH other topic documented here.
\title{Identification of GVEC}
\description{
Identifies performs one of the two versions of the identification algorithm described in Arbues, Ledo (2013).
This function is called by autoGVEC once the VAR order is identified. Also, here the deterministic terms are fixed.
}
\usage{
GVECid(x, p, eps1, eps2)
}
%- maybe also 'usage' for other objects documented here.
\arguments{
  \item{x}{
A multivariate series.
}
  \item{p}{
Order of the VAR.}
  \item{eps1}{
Margin or tolerance for the approximate Smith algorithm. }
  \item{eps2}{
Margin or tolerance to separate unit roots (usually, equal to \code{eps1}).
}
}
\details{
%%  ~~ If necessary, more details than the description above ~~
}
\value{
A list with the following: 
\item{PHI}{Polynomial matrix of the VAR.}
\item{deltas}{list of distinct polynomials of the main diagonal of the Smith form.}
\item{D}{Smith form.}
}
\references{
%% ~put references to the literature/web site here ~
}
\author{
%%  ~~who you are~~
}
\note{
%%  ~~further notes~~
}

%% ~Make other sections like Warning with \section{Warning }{....} ~

\seealso{
%% ~~objects to See Also as \code{\link{help}}, ~~~
}
\examples{
##---- Should be DIRECTLY executable !! ----
##-- ==>  Define data, use random,
##--	or do  help(data=index)  for the standard data sets.

## The function is currently defined as
function (x, p, eps1, eps2) 
{
    T = length(x)
    n = ncol(x)
    s = frequency(x)
    modfit = ar.burg(x, aic = F, order.max = p)
    PHI = ar2PM(modfit)
    smithPHI = smith(PHI, eps1)
    deltas = list()
    for (i in 1:n) {
        allroots = solve(smithPHI$D[i, i])
        unitr = which(abs(allroots) < (1 + eps2))
        newdelta = poly.from.roots(maproots(allroots[unitr], 
            s))
        if (i == 1) 
            deltas = c(deltas, list(newdelta))
        else {
            if (any(multp(newdelta, s) < multp(deltas[[length(deltas)]], 
                s))) {
                flag = T
                eps2loc = eps2
                while (flag) {
                  eps2loc = eps2loc * 1.01
                  cat("increasing eps2: ", eps2loc, "\n")
                  unitr = which(abs(allroots) < (1 + eps2loc))
                  newdelta = poly.from.roots(maproots(allroots[unitr], 
                    s))
                  if (all(multp(newdelta, s) >= multp(deltas[[length(deltas)]], 
                    s)) | eps2loc > 0.5) {
                    flag = F
                  }
                }
            }
            if (!(identical(deltas[[length(deltas)]], newdelta))) {
                deltas = c(deltas, list(newdelta))
            }
        }
    }
    return(list(PHI = PHI, deltas = deltas, D = smithPHI$D))
  }
}
% Add one or more standard keywords, see file 'KEYWORDS' in the
% R documentation directory.
\keyword{ ~kwd1 }
\keyword{ ~kwd2 }% __ONLY ONE__ keyword per line
